package com.example.android_entrainement;

import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class MainActivity extends Activity {

     public static final String EXTRA_MESSAGE = "com.example.android_entrainement.MESSAGE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //placeholder bitmap for empty spaces in gallery
        //Bitmap placeholder;
        //placeholder = BitmapFactory.decodeResource(getResources(), R.drawable.img1);


        ImageView iw= (ImageView)findViewById(R.id.card_imageView1);
        //iw.setImageBitmap(placeholder);

        WebImage image = (WebImage) findViewById(R.id.card_WebImage);
        image.startLoading("http://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/300px-PNG_transparency_demonstration_1.png");


       // ImageView iw= (ImageView)findViewById(R.id.card_imageView1);
       // try{
       // iw.setImageBitmap(getBitmapFromAsset("img10.png"));
       // }
      //  catch (IOException e)
      //  {}
    }

    /**
     * Helper Functions
     * @throws java.io.IOException
     */
    private Bitmap getBitmapFromAsset(String strName) throws IOException
    {
        AssetManager assetManager = getAssets();

        InputStream istr = assetManager.open(strName);
        Bitmap bitmap = BitmapFactory.decodeStream(istr);
        istr.close();

        return bitmap;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void sendMessage (View myView)
    {
        Intent intent = new Intent(this,DisplayMessageActivity.class);
        startActivity(intent);
    }

    public void OpenGallery(View myView)
    {
        Intent intent = new Intent(this,CardPicSelectActivity.class);
        startActivity(intent);
    }


}
